package be.groept.ace.cursusplanning.utils.observer;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;


public class PropertyChanged<T> implements Subject<T> {

	private List<Subscriber<T>> subscribers;
	
	public PropertyChanged() {
		subscribers = new ArrayList<Subscriber<T>>();
	}
	
	@Override
	public void addSubscriber(Subscriber<T> subscriber) {
		subscribers.add(subscriber);
	}

	@Override
	public void removeSubscriber(Subscriber<T> subscriber) {
		subscribers.remove(subscriber);
	}

	@Override
	public void notifySubscribers(EventArgs<T> event) {
		for(Iterator<Subscriber<T>> i = subscribers.iterator(); i.hasNext();) {
			i.next().update(event);
		}
	}
	
}